﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cashier
{
    class FormManager
    {
        private static List<Form> listForms = new List<Form>();
        public static void pushForm(Form f)
        {
            int count = listForms.Count;
            if (count > 0)
            {
                listForms[count - 1].Hide();
                f.Show();
                listForms.Add(f);
            }
            else
            {
                listForms.Add(f);
            }
        }
        public static void popForm()
        {
            int count = listForms.Count;
            if (count > 0)
            {
                //listForms[count - 1].Close();
                listForms.RemoveAt(count - 1);
                count = listForms.Count;
                if (listForms.Count == 0)
                    Application.Exit();
                else
                    listForms[count - 1].Show();
            }
        }

        public static void popAndCloseForm()
        {
            int count = listForms.Count;
            if (count > 0)
            {
                listForms[count - 1].Close();
                listForms.RemoveAt(count - 1);
                count = listForms.Count;
                if (listForms.Count == 0)
                    Application.Exit();
                else
                    listForms[count - 1].Show();
            }
        }
    }
}
